package icom.acm.action;

import icom.acm.bean.T_POSITION;
import icom.acm.manager.T_PositionMgr;

public class PositionAction extends Action{
	private T_POSITION pos;
	private String token;
	
	public String record() throws Exception {
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_PositionMgr tpm = new T_PositionMgr();
		tpm.insert(pos);
		return "SUCCESS";
	}
	
	public String delete(){
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_PositionMgr tpm = new T_PositionMgr();
		tpm.delete(pos.getP_ID());
		return "SUCCESS";
	}
	
	public String update(){
		String token = (String)session.getAttribute("token");
		if (token==null){
			return "ERROR";
		} else if (!token.equals(this.token)){
			return "ERROR";
		}
		session.removeAttribute("token");
		T_PositionMgr tpm = new T_PositionMgr();
		int id = tpm.update(pos);
		if(id == -1){
			return "ERROR";
		}
		return "SUCCESS";
	}
	
	public T_POSITION getPos() {
		return pos;
	}
	public void setPos(T_POSITION pos) {
		this.pos = pos;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
}
